<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表单</title>
    <link rel="stylesheet" href="__STATIC__/frame/layui/css/layui.css">
    <link rel="stylesheet" href="__STATIC__/frame/static/css/style.css">
    <link rel="stylesheet" href="__STATIC__/css/maowenke.css">
    <link rel="icon" href="__STATIC__/frame/static/image/code.png">
</head>
<body class="body">
<form id="form" method="post">
<div class="layui-row">
    <div class="layui-col-xs4">
        <select name="classes_id" class="layui-select" style="width: 90%">
            <option value="">请选择一级分类</option>
            {foreach $class as $value}
            <option value="{$value['id']}">{$value['class_name']}</option>
            {/foreach}
        </select>
    </div>
    <div class="layui-col-xs4">
        <select name="branch_id" class="layui-select" style="width: 90%">
            <option value="">请选择二级分类</option>
        </select>
    </div>
    <div class="layui-col-xs4">
        <select name="three_level_id" class="layui-select" style="width: 90%">
            <option value="">请选择三级分类</option>
        </select>
    </div>
</div>
    <div class="layui-form-item layui-form-text" style="margin-top: 15px">
        <label class="layui-form-label">题干</label>
        <div class="layui-input-block">
            <textarea name="stem" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text" style="margin-top: 15px">
        <label class="layui-form-label">图片</label>
        <div class="file">
            <input type="file" name="picture" >预览图片
        </div>
    </div>
    <div class="layui-form-item layui-form-text" style="margin-top: 15px">
        <label class="layui-form-label">预览</label>
        <div class="show">

        </div>
    </div>
<div class="layui-form-item layui-form-text" style="margin-top: 15px">
    <label class="layui-form-label">答案</label>
    <div class="layui-input-block">
        <textarea name="answer" placeholder="请输入答案，答案以中文'；。',英文';'分开" class="layui-textarea"></textarea>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">正确答案</label>
    <div class="layui-input-block">
        <input type="text" name="right_key" required  lay-verify="required" placeholder="请输入正确答案A,B,C,D...." autocomplete="off" class="layui-input">
    </div>
</div>
<div class="layui-form-item layui-form-text">
    <label class="layui-form-label">做题思路</label>
    <div class="layui-input-block">
        <textarea name="thinking" placeholder="请输入做题思路" class="layui-textarea"></textarea>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">获取的金币</label>
    <div class="layui-input-block">
        <input type="number" name="coin" required  lay-verify="required" placeholder="请输入获取金币数量" autocomplete="off" class="layui-input">
    </div>
</div>
    <div class="layui-form-item">
        <label class="layui-form-label">获取的经验</label>
        <div class="layui-input-block">
            <input type="number" name="experience" required  lay-verify="required" placeholder="请输入经验值" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">题目模式</label>
        <div class="layui-input-block">
            <select name="type" class="layui-select">
                {foreach $situation as $value}
                <option value="{$value['id']}">{$value['situation_name']}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">难度星等</label>
        <div class="layui-input-block">
            <select name="difficulty" class="layui-select">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
            </select>
        </div>
    </div>
    <input type="text" name="status" value="1" style="display: none">
</form>
<div class="layui-row" style="text-align: center;margin-top: 30px">
    <button class="layui-btn" id="tijiao">提交</button>
</div>
<script src="__STATIC__/frame/layui/layui.all.js" charset="utf-8"></script>
<script src="__STATIC__/js/jquery.3.3.1.min.js" charset="utf-8"></script>
<script src="__STATIC__/js/maowenke.js" charset="utf-8"></script>
<script>
    $("[name=picture]").change(function () {
        showImages($(this),$(".show"),'50');
    });
$("#tijiao").click(function () {
    ajaxs($("#form"),"{:url('add/add_bank')}",function (data) {
        console.log(data);
        if(data.code==200){
            layer.msg(data.msg);
            setTimeout(function () {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            },1500);
        }else{
            layer.msg(data.msg);
        }
    })
});
$("[name=classes_id]").change(function () {
    get_branch();
});
$("[name=branch_id]").change(function () {
    var $branchid = $(this).val();
    getBank($branchid);
});
function get_branch() {
        var $id = $("[name=classes_id]").val();
        $.post("{:url('Api/get_Branch')}",{id:$id},function (data) {
            if(data.code==200){
                $("[name=branch_id]").empty();
                var $str = '';
                $.each(data.data,function (i,v) {
                    $str +='<option value="'+v.id+'">'+v.branch_name+'</option>';
                });
                $("[name=branch_id]").append($str);
                var $branchid = $("[name=branch_id]").val();
                getBank($branchid);
            }else{
                layer.msg(data.msg);
            }
        })
}
function getBank($branchid) {
    $.post("{:url('api/getBank')}",{id:$branchid},function (data) {
        console.log(data);
        $("[name=three_level_id]").empty();
        var $str = '';
        $.each(data.data,function (i,v) {
           $str +='<option value="'+v.id+'">'+v.three_level_name+'</option>';
        });
        $("[name=three_level_id]").append($str);
    })
}
</script>
</body>
</html>